<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN" > 
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>竞拍车辆商户管理</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="aucSplUsrSearchForm">
        <div class="fieldset1 clearFix">
        	<div class="FXBR">
	            <div class="fieldBox">
	                <div class="label">商户名称</div>
	                <div class="field">
	                    <input name="splNm" id="splNm" type="text" class="ui-textbox" value="" ligerui="width: 160">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">登录帐号</div>
	                <div class="field">
	                    <input name="usrNm" id="usrNm" type="text" class="ui-textbox" value="" ligerui="width: 160">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">联系人</div>
	                <div class="field">
	                    <input name="splLnkMan" id="splLnkMan" type="text" class="ui-textbox" value="" ligerui="width: 160">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">电话号码</div>
	                <div class="field">
	                    <input name="splTel" id="splTel" type="text" class="ui-textbox" value="" ligerui="width: 160">
	                </div>
	            </div>
            </div>
            
            <div class="clearFix"></div>
	            <div class="btnsBox formBtns notRight">
	               <span id="searchBtn" class="sq-button-round">查询</span>
	               <span id="clearBtn" class="sq-button-round">清空</span>
	               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
	               <span id="addBtn" class="sq-button-round">新增</span>
	            </div>
        	</div>
        </form>
    </div>
</div>
<div id="aucSplUsrGridId" class="sq-grid"></div>
</div>

<script type="text/javascript">
	var audSplUsrGrid = null;
	$(function () {
	    initForm();
		initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
		initEvent();
	});
	
	//初始化事件
	function initEvent(){
		searchBtnEvent();
	    clearBtnEvent();
	    addEvent();
	}
	
	//初始化列表
	function initGrid(){
		$("#aucSplUsrGridId").ligerGrid({
	    	url: '<%=path%>/auccar/aucsplusr/initList.do',
	    	method : 'get',
	    	parms:getSearchParams(),
	        columns: [
	            { display: '商户名称', name: 'splNm', minWidth: 300 , align:'left', enabledSort:true,
	            	render: function (rowdata, rowindex, value, column) { 
	            		if(StringUtils.isEmpty(value)){
	                		value = "";
	                	}
	            		var h = '';
	            		    h='<a href="javascript:showDetail(';
	                        h+="'"+rowdata.id+"'";
	                        h+=')">'+value+'</a>'
	                        return h;
	            		}},
	            { display: '登录帐号', name: 'usrNm', width: 120, enabledSort:true},
	            { display: '联系人', name: 'splLnkMan', width: 120,align:'left', enabledSort:true},
	            { display: '电话号码', name: 'splTel', width: 120, enabledSort:true},
	            { display: '所属区域', name:'area', width: 160, align:'center', enabledSort:true,
	            	render: function (rowdata, rowindex, value, column) { 
	            		if(StringUtils.isEmpty(value)){
	            			if(StringUtils.isEmpty(rowdata.rgnPrCdNm)){
	            				rowdata["rgnPrCdNm"] = "";
	            			}
	            			
	            			if(StringUtils.isEmpty(rowdata.rgnCyCdNm)){
	            				rowdata["rgnCyCdNm"] = "";
	            			}
	                		value = rowdata.rgnPrCdNm + "/" + rowdata.rgnCyCdNm;
	                	}
	            		return value;
	            	}},
	            { display: '帐号状态', name: 'isValid', width: 120, enabledSort:true,
	            	render: function (rowdata, rowindex, value, column) { 
	            		if(rowdata.isValid == 1){
	                		value = "启用";
	                	}else{
	                		value = "禁用";
	                	}
	            		return value;
            		}},
	            { display: '创建时间', name: 'crtTm', width: 180 , render:renderDate, enabledSort:true},
	            { display: '修改时间', name: 'mdfTm', width: 180 , render:renderDate, enabledSort:true},
	            getGridOperColumnContent()
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        rownumbers:true
	    });
	    audSplUsrGrid = liger.get("aucSplUsrGridId");
	    audSplUsrGrid.setHeight(100);
	    audSplUsrGrid.options.isSingleCheck=true;
	}
	
	//隐藏掉操作列
    function getGridOperColumnContent(){
    	var data = {
                display: '操作',
                isSort: false,
                width: 150,
                align:'left',
                render: function (rowdata, rowindex, value){
                    var h="";
                    	h+='<a class="sq-button-hasicon" alt="修改" href="javascript:modifyRow(';
                        h+="'"+rowdata.id+"'";
                        h+=",'ligergrid_bankacc'"
                        h+=")\"><i class=\"sqBtnIco_4\"></i>修改</a>"
                        
                        var state = "";
                        var statePic = "";
                        if(rowdata.isValid == 0){//反方向按钮
                        	state = "启用";
                        	statePic = "sqBtnIco_12";
                        }else if(rowdata.isValid == 1){
                        	state = "禁用";
                        	statePic = "sqBtnIco_13";
                        }
                        
                        h+='<a class="sq-button-hasicon" alt="启用/启用" href="javascript:modifyIsValidRow(';
                        h+="'"+rowdata.id+"'";
                        h+=",'"+rowdata.isValid+"'";
                        h+=",'ligergrid_bankacc'"
                        h+=")\"><i class=\""+statePic+"\"></i>"+state+"</a>";
                    return h;
                }
        	 }
        	return data;
	}
	
  //清空按钮事件
	function clearBtnEvent(){
		 $("#clearBtn").click(function(event) {
		       $("#resetBtn").click();
		 });
	}
	
	//初始化表单
	function initForm(){
		$("#aucSplUsrSearchForm").ligerForm();
	}
	
	//查询按钮事件
	function searchBtnEvent(){
		 $("#searchBtn").click(function(event) {
	         var form = new liger.get("aucSplUsrSearchForm");
	         var data = form.getData();
	         for (name in data){
	            audSplUsrGrid.setParm(name,data[name]);
	         };
	        audSplUsrGrid.reload();
	    });
	}
	
	//新增商户
	function addEvent(){
		//新增商户
        $("#addBtn").click(function(event) {
        	$.ligerDialog.SQopen({
                width: 800,
                height:400,
                title : '新增商户信息',
                urlParms:{},
                url:'<%=path%>/auccar/aucsplusr/toAddOrModifyPage.do',
                // 自定义buttons的时候 不要设置 fixButtons: true
                buttons: [{
                        text: "保存", type: 'ok', cls: 'l-dialog-btn-ok', 
                        onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onOk = function () {}
                            if (Dialog.onOk) {
                            	Dialog.onOk();
                            }
                        }
                    }, {
                        text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                        onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                            if (Dialog.onCancel) Dialog.onCancel();
                        }
                    }
                ]
            });
        });
	}
	
	//修改
	function modifyRow(_id){
    	$.ligerDialog.SQopen({
            width: 800,
            height:400,
            title : '修改商户信息',
            urlParms:{id:_id},
            url:'<%=path%>/auccar/aucsplusr/toAddOrModifyPage.do',
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                    text: "保存", type: 'ok', cls: 'l-dialog-btn-ok', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onOk = function () {}
                        if (Dialog.onOk) {
                        	Dialog.onOk();
                        }
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });
	}
	
	//修改是否有效
	function modifyIsValidRow(_id, _isValid){
		var isValid;
		if(_isValid == 1){//有效变无效
			isValid = 0;
			$.ligerDialog.confirm("确定禁用吗?", function (flag) {
        		if(flag == false)return;
        		var data = {};
                data["id"] = _id;
                data["isValid"] = isValid;
                var url = '<%=path%>/auccar/aucsplusr/modifyIsVliad.do';
                AjaxUtils.ajaxPost(url, data, modifyIsVliadCallback, true);
        	});
		}else if(_isValid == 0){//无效变有效
			isValid = 1;
			$.ligerDialog.confirm("确定启用吗?", function (flag) {
        		if(flag == false)return;
        		var data = {};
                data["id"] = _id;
                data["isValid"] = isValid;
                var url = '<%=path%>/auccar/aucsplusr/modifyIsVliad.do';
                AjaxUtils.ajaxPost(url, data, modifyIsVliadCallback, true);
        	});
		}
	}
	
	//回调
	function modifyIsVliadCallback(msg){
		 if(msg.success == 1){
			 UIUtils.alertSuccess(msg.info);
			 audSplUsrGrid.reload();
		 }else{
			 UIUtils.alertError(msg.info);
		 }
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("aucSplUsrSearchForm");
        var data = form.getData();
        return data;
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
	
	//删除数据
	function deleteRecord(){
		var selectedRows = audSplUsrGrid.getSelectedRows();
		if(selectedRows.length == 0){
			UIUtils.alertWarning(LogUtils.LOG_CMM_SELECT_MORE_ROW);
			return;
		}
		var _ids = [];
		for ( var index in selectedRows) {
			_ids.push(selectedRows[index].id);
		}
		$.ligerDialog.SQconfirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			var _url = "<%=path%>/customer/cstbscinfo/removeByIds.do";
			AjaxUtils.ajaxPost(_url, {ids:JSON.stringify(_ids)}, function(msg){
				if(msg.success == 1){
					 audSplUsrGrid.reload();
				 }else{
					 UIUtils.alertError(msg.info);
				 }
			},true);
		});
	};
	
	//查看数据
	function showDetail(_id){
		$.ligerDialog.SQopen({
            width: 800,
            height:400,
            title : '新增商户信息',
            urlParms:{id:_id},
            url:'<%=path%>/auccar/aucsplusr/toDetailPage.do',
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                    text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });
	}
	
	//保存
	function saveNpInfo(){
		if (!ligerPersonForm.valid()) {
            UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
            return false; //验证不通过，不执行以下代码
        }
        var data = ligerPersonForm.getData();
        
	}
	
	function clearBtn(){
		var form = new liger.get("aucSplUsrSearchForm");
		form.clear();
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
</script>

</body>
</html>
